Change reveal_type() representation of TypedDicts#3598
Merged
Conversation
Change the formatting to be closer to the TypedDict definition syntax and preserve TypedDict name when constructing using TD(...) for better reveal_type output. Note that this uses a new representation `'key'?: type` for non-required keys. I'll update remaining error messages to use the new syntax in a separate PR. Fixes #3590.
JukkaL
added a commit
that referenced
this pull request
Jun 23, 2017
Distinguish between required and non-required keys and use syntax that is closer to TypedDict definition syntax. This is follow-up to #3598.
ilinum
approved these changes
Jun 27, 2017
| fallback = self.chk.named_generic_type('typing.Mapping', | ||
| [self.chk.str_type(), mapping_value_type]) | ||
| return TypedDictType(items, set(callee.required_keys), fallback) | ||
| return callee |
Collaborator
There was a problem hiding this comment.
Is there a reason you do not create a new TypedDictType anymore?
Collaborator
There was a problem hiding this comment.
Oh, is that in order to preserve the original TypedDict name?
Collaborator
Author
There was a problem hiding this comment.
Yes. Also, the deleted code no longer serves its original purpose because of changes to TypedDict type inference.
ilinum
reviewed
Jun 27, 2017
| [builtins fixtures/dict.pyi] | ||
| [out1] | ||
| main:2: error: Revealed type is 'TypedDict(x=builtins.int, y=builtins.str, _fallback=m.D, _total=False)' | ||
| main:2: error: Revealed type is 'TypedDict('m.D', {'x'?: builtins.int, 'y'?: builtins.str})' |
Collaborator
There was a problem hiding this comment.
I think while the ?-syntax for non-required keys has its downsides, it works well in this case.
We need to be concise and I think ? is pretty intuitive.
It might be worth mentioning it documentation.
Collaborator
Author
There was a problem hiding this comment.
A good point. I'll update the docs tomorrow to mention ?.
ilinum
pushed a commit
that referenced
this pull request
Jun 27, 2017
Distinguish between required and non-required keys and use syntax that is closer to TypedDict definition syntax. This is follow-up to #3598.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Change the formatting to be closer to the TypedDict definition syntax
and preserve TypedDict name when constructing using TD(...) for better
reveal_type output.
Note that this uses a new representation
'key'?: typefornon-required keys.
I'll update remaining error messages to use the new syntax in a
separate PR.
Fixes #3590.